import 'package:flutter/material.dart';
import 'package:fluwx_no_pay/fluwx_no_pay.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../fluwx_util.dart';
import 'model.dart';

showShare() {
  if (Get.context == null) {
    return;
  }
  List<ShareModel> items = [
    ShareModel(title: '微信', icon: 'images/icon_wechat.png'),
    ShareModel(title: '朋友圈', icon: 'images/icon_wechat.png'),
    ShareModel(title: '微博', icon: 'images/umeng_socialize_share_web.png'),
  ];
  showModalBottomSheet(
      context: Get.context!,
      backgroundColor: const Color(0xffeeeeee),
      isScrollControlled: true,
      builder: (context) {
        return Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              padding: EdgeInsets.only(top: 20.r),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  SizedBox(
                    width: double.infinity,
                    child: Wrap(
                      alignment: WrapAlignment.spaceEvenly,

                      children: items
                          .asMap()
                          .map(
                            (key, value) => MapEntry(
                              key,
                              InkWell(
                                onTap: () {
                                  if (key == 0) {
                                    shareToWx(WeChatScene.SESSION);
                                  } else if (key == 1) {
                                    shareToWx(WeChatScene.TIMELINE);
                                  }
                                },
                                child: Column(
                                  children: [
                                    Image.asset(value.icon,
                                        fit: BoxFit.cover,
                                        width: 35.r, height: 35.r),
                                    Text(
                                      value.title,
                                      style: TextStyle(
                                          color: const Color(0xff333333),
                                          fontSize: 15.sp),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          )
                          .values
                          .toList(),
                    ),
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  InkWell(
                    onTap: Get.back,
                    child: Container(
                      // padding: EdgeInsets.only(bottom: Get.s),
                      alignment: Alignment.center,
                      width: double.infinity,
                      height: 50.r,
                      color: Colors.white,
                      child: Text(
                        '取消',
                        style: TextStyle(
                            color: const Color(0xff333333), fontSize: 14.sp),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ],
        );
      });
}

void shareToWx(WeChatScene scene) {
  var md = WeChatShareWebPageModel('https://www.baidu.com',
      title: '分享标题',
      thumbnail: WeChatImage.asset('images/icon_wechat.png'),
      scene: scene);
  WXUtil().share(md);
}
